import Api from '@/api/api.js'
import * as userApi from '@/api/user.js'
import * as bootApi from '@/api/bootstrappers.js'

export default {
  // 注销登录
  async SIGN_OUT({ commit }) {
    const { data } = await Api.post('/user/logout')
    if (1 !== data.code) return
    commit('SIGN_OUT')
  },
  async getBootstrappers({ commit }) {
    const { data, status } = await bootApi.getBootstrappers()
    if (200 !== status) return
    commit('SAVE_CONFIG', data)
    return data || {}
  },
  async fetchUserInfo({ commit }, user = null) {
    if (user) {
      commit('SAVE_CURRENTUSER', user || {})
      return user || {}
    } else {
      const { data } = await userApi.fetchUserInfo()
      commit('SAVE_CURRENTUSER', data.data || {})
      return data || {}
    }
  }
}
